package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.RoutePointDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.IRoutePointConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/Point" }) // getCommonPlacePage
@Api("RoutePointController相关api")
@CrossOrigin
public class RoutePointController {

	@Autowired

	private IRoutePointConsumeService iRoutePointConsumeService;

	/**
	 * 途径点信息-分页
	 * 
	 * @param page
	 *            分页参数
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@GetMapping(value = { "/getSchemeInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation(value = "途径点信息分页", notes = "途径点分页")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "routePointId", value = "途径点编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "pathPointName", value = "途径点名称", paramType = "query", dataType = "string")})
	public ResultPojo getSchemeInfoPage(@RequestParam(defaultValue = "") String routeId,
			@RequestParam(defaultValue = "") String routePointId, @RequestParam(defaultValue = "") String pathPointName, Page page, HttpServletRequest request) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iRoutePointConsumeService.getPointPage(page, routeId, routePointId, pathPointName);
		return resultPojo;
	}

	/**
	 * 途径点信息-list
	 * 
	 * @return
	 */
	@GetMapping(value = { "/getRoutePointList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = RoutePointDto.class, code = 0, message = "")
	@ApiOperation("途径点信息List集合")
	@ApiImplicitParams({ 
		@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "routePointId", value = "途径点编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "routePointName", value = "途径点名称", paramType = "query", dataType = "string")})
	public ResultPojo getRoutePointList(@RequestParam(defaultValue = "") String routeId,
			@RequestParam(defaultValue = "") String routePointId, @RequestParam(defaultValue = "") String routePointName,HttpServletRequest request) {
		ResultPojo resultPojo = iRoutePointConsumeService.getPointList(routeId, routePointId, routePointName);
		return resultPojo;
	}
	
	/**
	 * 途径点添加（单条数据）；
	 * 
	 */
	@PostMapping(value = { "/addRoutePoint" }, consumes = { "application/json; charset=UTF-8" }, produces = {
	"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加线路途径点")
	public ResultPojo addRoutePoint(@RequestBody RoutePointDto routePointDto, HttpServletRequest request) {
		return iRoutePointConsumeService.insertRoutePoint(routePointDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 删除途径点（传线路编号或者途径点编号）
	 * 
	 */
	@DeleteMapping(value = { "/delRoutePoint" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除途径点信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pointId", value = "途径点编号", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "routeId", value = "线路编号", paramType = "query", dataType = "string")})
    public ResultPojo delRoutePoint(
    		@RequestParam(defaultValue = "",value="pointId",required=true) String pointId,
			@RequestParam(defaultValue = "",value="routeId",required=false) String routeId, 
			HttpServletRequest request) {
        return iRoutePointConsumeService.deleteRoutePoint(pointId,routeId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
}
